<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-calendar"></i> 分配视频
                </el-breadcrumb-item>
                <el-breadcrumb-item>分配视频到课程</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="form-box">
                <el-form ref="form" :model="msgform" label-width="80px">
                    <el-form-item label="课程">
                        <el-select v-model="value1" filterable placeholder="请选择">
                            <el-option
                                    v-for="item in courses"
                                    :key="item.courseid"
                                    :label="item.coursename"
                                    :value="item.courseid">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="视频">
                        <el-select v-model="value2" filterable placeholder="请选择">
                            <el-option
                                    v-for="item in mvs"
                                    :key="item.mvid"
                                    :label="item.mvname"
                                    :value="item.mvid">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">确定</el-button>
                        <el-button>取消</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
    import {getAllCourse, addMvToCourse, getAllMv} from "../../api/admin";

    export default {
        name: 'baseform',
        data() {
            return {
                options: [{
                    userid: '',
                    username: ''
                }],
                courses:[{
                    courseid:'',
                    coursename:'',
                }],
                mvs:[{
                    mvid:'',
                    mvname:'',
                }],
                value: '',
                value1:'',
                value2:'',
                msgform: {
                    name: '',
                    region: '',
                    date1: '',
                    date2: '',
                    delivery: true,
                    type: ['步步高'],
                    resource: '小天才',
                    desc: '',
                    options: []
                },
                param: {
                    title:'',
                    value1:'',
                    content:'',
                    value2:'',

                },
                query: {
                    userid:''
                }
            };
        },
        created() {
            this.getData();
        },
        methods: {
            getData() {
                // let user1 = JSON.parse(localStorage.getItem('user'));
                // this.query.userid=user1.userid;
                // getReceiverList(this.query).then(res => {
                //     console.log(res);
                //     this.options=res.data;
                //     this.param.title='';
                //     this.value='';
                //     this.param.content='';
                // });
                getAllCourse().then(res =>{
                   console.log(res);
                   this.courses=res.data;
                   this.value1='';
                });
                getAllMv().then(res =>{
                    console.log(res);
                    this.mvs=res.data;
                    this.value2='';
                });
            },
            onSubmit() {
                // let user = JSON.parse(localStorage.getItem('user'));
                // this.param.value=this.value;
                this.param.value1=this.value1;
                this.param.value2=this.value2;
                addMvToCourse(JSON.stringify({'mvid':this.param.value2,'courseid':this.param.value1})).then(res =>{
                    console.log(res);
                    if (res.state==2000){
                        this.$message.success('添加成功！');
                        location.reload();
                    }else{
                        this.$message.error(res.message);
                    }
                })
            }
        }
    };
</script>
